package seatiger.tomcat.catalina.core;

import seatiger.tomcat.catalina.Constants;
import seatiger.tomcat.catalina.Container;
import seatiger.tomcat.catalina.Mapper;
import seatiger.tomcat.catalina.Request;
import seatiger.tomcat.util.StringManager;

/**
 * StandardEngine的映射器
 */
@Deprecated
public class StandardEngineMapper implements Mapper {
    private StandardEngine engine;

    private String protocol;

    private static final StringManager sm = StringManager.getManager(Constants.PACKAGE_CORE);

    @Override
    public Container getContainer() {
        return this.engine;
    }

    @Override
    public void setContainer(Container container) {
        if (!(container instanceof StandardEngine))
            throw new IllegalArgumentException(sm.getString("httpEngineMapper.container"));
        engine = (StandardEngine) container;
    }

    @Override
    public String getProtocol() {
        return this.protocol;
    }

    @Override
    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    @Override
    public Container map(Request request, boolean update) {
        String serverName = request.getRequest().getServerName();
        return engine.findChild(serverName);
    }
}
